package com.jt.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jt.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    @Select("select id,username,password,status " +
            "from tb_users " +
            "where username=#{username}")
    User selectUserByUsername(String username);

    /**
     *基于用户id查询用户权限，涉及的表有
     * tb_user_roles(用户角色关系表，可以在此表中基于用户id找到用户角色)
     * tb_role_menus(角色菜单关系表，可以基于角色id找到菜单id)
     * tb_menus(菜单表，表单为资源外在表现形式，在此表中可以基于菜单id找到权限标识)
     * */
    @Select("select tm.permission from tb_user_roles url join tb_role_menus trm on url.role_id = trm.role_id join tb_menus tm on trm.menu_id = tm.id where url.role_id = #{userId}")
    List<String> selectUserPermissions(Long userId);
}
